package com.vieewer.btdemo.view.notification;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.WindowManager;
import android.widget.TextView;
import com.lindroid.androidutilskt.extension.SpUtil;
import com.vieewer.btdemo.R;
import com.vieewer.btdemo.bean.NotificationBean;

public class DialogActivity extends Activity {

    int delayMillis = 3;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);

        delayMillis = SpUtil.getSpInt("SP_KEY_NOTIFICATION_TIME", 3);

        Log.i("DialogActivity", "show seconds = " + delayMillis);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
                WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        initViews();

        new Handler().postDelayed(() -> DialogActivity.this.finish(), delayMillis*1000);

    }

    private void initViews() {
        TextView txt_app_name = findViewById(R.id.txt_app_name);
        TextView txt_title = findViewById(R.id.txt_title);
        TextView txt_content = findViewById(R.id.txt_content);

        NotificationBean data = (NotificationBean) getIntent().getSerializableExtra("data");
        if (data != null) {
            txt_app_name.setText(data.name);
            txt_title.setText(data.title);
            txt_content.setText(data.text);
        }
    }
}
